#define _CRT_SECURE_NO_WANINGS 1
#pragma warning(disable: 4996)


class Solution
{
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals)
    {
        sort(intervals.begin(), intervals.end());

        vector<vector<int>> res;
        int rn = 0;
        for (int i = 0; i < (int)intervals.size(); i++)
        {
            int s = intervals[i][0], e = intervals[i][1];
            if (rn == 0 || res.back()[1] < s)
            {
                res.push_back(intervals[i]);
                rn++;
            }
            else
            {
                res.back()[1] = max(res.back()[1], e);
            }
        }

        return res;
    }
};